package input;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

import core.Vector2;

public class Mouse implements MouseListener, MouseMotionListener, MouseWheelListener {

    public static boolean[] mouseClicked = new boolean[5];
    public static boolean[] mousePressed = new boolean[5];
    public static boolean[] mouseDragged = new boolean[5];
    
    private static Vector2 mousePos = new Vector2(0 ,0);
    private static boolean mouseWheelMoved = false;
    private static int mouseWheel;
   
    private static Vector2 lastMousePos = new Vector2(0, 0);
    private static boolean mouseReleased = false;

	@Override
	public void mouseDragged(MouseEvent e) {
		mouseDragged[e.getButton()] = true;
		mousePos.setPos(e.getX(), e.getY());
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		mousePos.setPos(e.getX(), e.getY());
		lastMousePos.setPos(mousePos);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		mouseClicked[e.getButton()] = true;
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	    mousePressed[e.getButton()] = true;
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		mouseClicked[e.getButton()] = false;
	    mousePressed[e.getButton()] = false;
		mouseDragged[e.getButton()] = false;
		mouseReleased = true;
	}
	
	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		mouseWheelMoved = true;
		mouseWheel = e.getWheelRotation();
	}
	
	public static Vector2 getPos() {
		return mousePos;
	}
	
	public static Vector2 lastPos() {
		return lastMousePos;
	}
	
	public static boolean released() {
		boolean released = mouseReleased;
		mouseReleased = false;
		return released;
	}
    
	public static int getMouseWheelRotation() {
		if(!mouseWheelMoved) {
			return 0;
		} else {
			mouseWheelMoved = false;
			return mouseWheel;
		}
	}
}
